package com.sgb.kjwl.viewmodel.self;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.user.CompanyInfoEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.JoinCompanyActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class JoinComModel extends BaseViewModel {
    private JoinCompanyActivity activity;
    private SelfRepertory repertory;
    private int page = 1;
    private int size = 10;
    public String text = "";

    public JoinComModel(JoinCompanyActivity activity, SelfRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void getCompanyListModel(String type, String text, boolean isLoadMore, boolean isEdit) {
        if (!isEdit)
            DialogHelper.showProgressDialog(activity, null, "正在加载...", 0, false, null).setCanceledOnTouchOutside(false);
        this.text = text;
        page = isLoadMore ? page + 1 : 1;
        Map<String, Object> map = new HashMap();
        map.put("pageNum", page);
        map.put("pageSize", size);
        map.put("type", type);
        map.put("text", text);
        APIManager.getInstance().getUserAPI().newSearchCompanyByText(map)
                .enqueue(new ICallBack<BaseEntity<ListResponse<List<CompanyInfoEntity>>>>() {
                    @Override
                    public void onSuccess(BaseEntity<ListResponse<List<CompanyInfoEntity>>> data) {
                        if (!isEdit)
                            DialogHelper.dismissProgressDialog();
                        if (data.getData().getList() != null)
                            activity.showListData(data.getData().getList(), isLoadMore);
                    }
                });
    }
}
